<?php
function __autoload($name){
	include '../class/'.strtolower($name).'.class.php';
}
if($_POST['action']!='getSideBar')
	return 'error';
function ruler($str,$len){			/**长度超出len，只取len个字节，必须是3*2的倍数**/
	if(strlen($str)>$len)			/********  中文 utf-8 3byte  gbk 2byte  ********/
		$str=substr($str,0,$len).'......';
	return $str;
}
$art=new Article;
/*分类 CATegory*/
$cat='<ul>';
$type=$art->getCategory();
for($i=0;$t=$type[$i];$i++)
	$cat.='<li><a href="#">'.$t.'</a></li>';
$cat.='</ul>';

/*最新评论 Latest Comments*/
$lc='<dl>';
$c=$art->getLatestComments($_POST['latestCommentsNum']);
$count=count($c);
for($i=0;$i<$count;$i++){	
	$replier=$c[$i]['replier'];
	$replier=$replier?$replier:'游客';
	$lc.='<dt><b>'.$replier.':</b></dt>';
	$cont=$c[$i]['content'];

	$lc.='<dd  style="border-bottom:1px solid #D3D3D3">';
	$lc.='<a href="#article" onclick="showDetail('.$c[$i]['blog_id'].',1)">'.ruler($cont,78).'</a></dd>';
}
$lc.='</dl>';


/*浏览排行 Highest Click*/
$hc='<table>';
$cl=$art->getHighestClick($_POST['highestClickNum']);
$count=count($cl);
for($i=0;$i<$count;$i++){	//$cl[$i]['aid']
	$hc.='<tr style="border-bottom:1px solid #D3D3D3;vertical-align:top">';
	$hc.='<td style="color:#D3D3D3">'.$cl[$i]['click_count'].'</td>';
	$hc.='<td><a href="#article" onclick="showDetail('.$cl[$i]['id'].',1)">['.ruler($cl[$i]['category'],78).']'.$cl[$i]['title'].'</a></td>';
	$hc.='</tr>';
}
$hc.='<table>';
$output='{"category":\''.addslashes($cat).'\',"latestComments":\''.addslashes($lc).'\',"highestClick":\''.addslashes($hc).'\'}';
echo $output;
